/* eslint-disable no-unused-vars */
import config from './config'
import axios from 'axios'
import encode from '@/utils/encryption/index'
import Qs from 'qs'
export const deleteObj = (data) => axios.post(config.deleteObj, normalPost(data))
export const downloadByThink = (data) => axios.post(config.downloadByThink, normalPost(data), {responseType: 'blob'})
export const streamDownloadByThink = (data) => axios.post(config.streamDownloadByThink, normalPost(data), {responseType: 'blob'})
export const download = (data) => axios.post(config.download, normalPost(data), {responseType: 'blob'})
export const streamDownload = (data) => axios.post(config.streamDownload, normalPost(data), {responseType: 'blob'})
export const getObjectList = (data) => axios.post(config.getObjectList, normalPost(data))
export const getXyqServerList = (data) => axios.post(config.getXyqServerList, normalPost(data))
export const getXyqTraList = (data) => axios.post(config.getXyqTraList, normalPost(data))
export const deleteObjThink = (data) => axios.post(config.deleteObjThink, normalPost(data))
export const getObjectListByThink = (data) => axios.post(config.getObjectListByThink, normalPost(data))
export const getMsg = (data) => axios.post(config.getMsg, normalPost(data))
export const getBackMsg = (data) => axios.post(config.getBackMsg, normalPost(data))
export const Upload = (fromData) => axios.post(config.Upload, fromData, {responseType: 'blob'}, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })

export const uploadImgByThink = (fromData) => axios.post(config.uploadImgByThink, fromData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
export const uploadImg = (fromData) => axios.post(config.uploadImg, fromData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
})

/**
     * 处理输入参数
     * @param {Object} data json
     * @return {String} json字符串
     */
function normalPost(data) {
  return Qs.stringify(data)

}

/**
      * 处理输入参数
      * @param {Object} data 传输请求数据
      * @return {String} 返回加入token后的加密数据
      */
function encryptionTokenPost(data) {
  data.token = JSON.parse(sessionStorage.getItem('token'))
  return Qs.stringify(encode.selfEncrypt(data))
}
